version 14.1
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.VII OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

*-----------------------------------
* 	WITHOUT CONTROLS
*-----------------------------------

/* DEFINING TIME VARIABLE */		

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==0
sort			regnor year
local 			var="seinc"
local			lbound=80000
local			ubound=500000

/* LOG CHANGE IN EARNINGS */

keep 			`var' regnor year industry2 taxableinc location_code
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>80000 & z0<=500000
keep			if year<=2008
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) & year<2011

/* GENERATING TREATMENT DUMMIES */

g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2008)
g				t_09=(`var'>400000 & year==2008)
g				trend=1
local			i=1
forvalues		y=2007/2008 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2007

/* COLUMN (1) */

local			i=1
local			j=1
qui				reg logchange i.year tozero nottozero m_09 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)

/* COLUMN (2) -- LINEAR */

local			i=1
local			j=`j'+1
qui				reg logchange trend tozero nottozero m_09 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)

/* COLUMN (3) -- INDUSTRY-SPECIFIC */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.industry2 tozero nottozero m_09 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (4) -- INDUSTRY-FE */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.industry2 tozero nottozero m_09 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (5) -- REGION-FE */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero m_09 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & location_code>0
matrix			table[`i',`j']=r(mean)

/* COLUMN (6) -- REGUION-SPECIFIC */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.location_code tozero nottozero m_09 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & location_code>0
matrix			table[`i',`j']=r(mean)

/* COLUMN (7) -- REGUION-SPECIFIC & INDUSTRY-SPECIFIC */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.location_code i.year*i.industry2 tozero nottozero m_09 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=. & location_code>0
matrix			table[`i',`j']=r(mean)

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
drop			table8-table9
keep			if _n<=6
g				c11=""
replace			c11="$\mbox{\emph{to-zero}} \times 2008$" in 1
replace			c11="$\mbox{\emph{not-to-zero}} \times 2008$" in 3
replace			c11="Observations" in 5
forvalues 		c=1/7 {
g				c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)4 {
forvalues		c=1/7 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/7 {
replace			c`c'=string(table`c',"%15.0fc") in 5
}
forvalues		s=1/8 {
g				s`s'="&"
}
g				l="\\"
replace			l="\\\\" in 4
browse			c11 s8 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 l
